package com.josephxu.tank;

/**
 * @Author: Joseph Xu
 * @Date: 2022/1/27 22:18
 */
public class FourDirFireStrategy implements FireStrategy {

    private static volatile FourDirFireStrategy fourDirFireStrategy;

    private FourDirFireStrategy(){

    }

    public static FourDirFireStrategy getInstance(){
        if (fourDirFireStrategy ==null){
            fourDirFireStrategy = new FourDirFireStrategy();
        }
        return fourDirFireStrategy;
    }

    @Override
    public void fire(Tank tank) {
        int bx = tank.getX() + Tank.WIDTH/2 - Bullet.WIDTH/2;
        int by = tank.getY() + Tank.HEIGHT/2 - Bullet.HEIGHT/2;
        for (Dir dir : Dir.values()) {
            new Bullet(bx,by,dir,tank.getGroup(),tank.tf);
        }
        if(tank.getGroup() == Group.GOOD) new Thread(()->new Audio("audio/tank_fire.wav").play()).start();

    }
}
